package com.rc.web.controller;

import com.mybatisflex.core.paginate.Page;
import com.rc.common.annotate.WithoutTenant;
import com.rc.pojo.dto.plantItem.PlantItemAddDTO;
import com.rc.pojo.dto.plantItem.PlantItemQuery;
import com.rc.pojo.dto.plantItem.PlantItemUpdateDTO;
import com.rc.pojo.vo.plantitem.PlantItemDetailVO;
import com.rc.pojo.vo.plantitem.PlantItemPageVO;
import com.rc.pojo.vo.plantitem.PlantItemVO;
import com.rc.web.service.PlantItemService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 活动表 控制层。
 *
 * @author sym
 * @since 2024-05-26
 */
@RestController
@RequestMapping("/plantItem")
@Api(tags = "作物详情")
@RequiredArgsConstructor
@Validated
public class PlantItemController {
    private final PlantItemService plantItemService;

    @PostMapping
    @ApiOperation("添加作物")
    public void add(@RequestBody PlantItemAddDTO dto){
        plantItemService.add(dto);
    }

    @DeleteMapping("/{id}")
    public void deleteOneById(@PathVariable Long id){
         plantItemService.deleteOneById(id);
    }

    @PutMapping
    public void updateOneById(@RequestBody PlantItemUpdateDTO dto){
        plantItemService.updateOneById(dto);
    }

    @GetMapping("/{id}")
    public PlantItemVO getOneById(@PathVariable Long id){
        return plantItemService.getOneById(id);
    }

    @GetMapping("/detail/{id}")
    @ApiOperation("查看植物详情")
    @WithoutTenant
    public PlantItemDetailVO getDetail(@PathVariable Long id) {
        return plantItemService.getDetail(id);
    }

    @GetMapping("/page")
    public Page<PlantItemPageVO> getPage(PlantItemQuery query){
        return plantItemService.getPage(query);
    }
}
